package com.app.biz.service.impl;

import cn.hutool.core.date.DateUtil;
import com.app.biz.domain.CompanyAnalysis;
import com.app.biz.mapper.CompanyAnalysisMapper;
import com.app.biz.service.ICompanyAnalysisService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CompanyAnalysisServiceImpl implements ICompanyAnalysisService {

    private final CompanyAnalysisMapper companyAnalysisMapper;

    public CompanyAnalysisServiceImpl(CompanyAnalysisMapper companyAnalysisMapper) {
        this.companyAnalysisMapper = companyAnalysisMapper;
    }

    @Override
    public List<CompanyAnalysis> getCityCompanyCountAnalysis() {
        //获到今年减一年
        Date currentDate = DateUtil.date();
        int year = DateUtil.year(currentDate);
        List<CompanyAnalysis> list = companyAnalysisMapper.getCityCompanyCountAnalysis(String.valueOf(year - 1));
        if(list != null && list.size() > 0){
            list.forEach(item -> {
                if(item.getCompanyTotalCount() > item.getUnFinishCompanyCount()){
                    item.setFinishDesc("未完成");
                }else{
                    item.setFinishDesc("已完成");
                }
            });
        }
        return list;
    }
}
